package util

import (
	"fmt"

	"github.com/atotto/clipboard"
	dclip "golang.design/x/clipboard"
)

// CopyTextToClipboardIgnoreError 将字符串写入剪切板，忽略错误
func CopyTextToClipboardIgnoreError(text string) {
	if err := clipboard.WriteAll(text); err != nil {
		fmt.Println("warning: copy to clipboard failed")
	}
}

// PrintAndCopyTextToClipboardIgnoreError 将字符串写入剪切板，忽略错误，并在控制台打印
func PrintAndCopyTextToClipboardIgnoreError(text string) {
	CopyTextToClipboardIgnoreError(text)
	fmt.Println(text)
}

// ReadImageFromClipboard 从剪切板读取图片
func ReadImageFromClipboard() (raw []byte) {
	return dclip.Read(dclip.FmtImage)
}

// ReadTextFromClipboard 从剪切板读取文字
func ReadTextFromClipboard() (res string) {
	return string(dclip.Read(dclip.FmtText))
}
